package com.shen.JUC.volatileTest;

import java.util.concurrent.TimeUnit;

public class JMM {
    //不加volatile，程序就会死循环，volatile可以保证可见性
    private volatile static int num=0;
    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            while (num==0){

            }
        }).start();
        TimeUnit.SECONDS.sleep(1);
        num=1;
        System.out.println(num);
    }
}
